package com.example.swd1.gudong.main.user.runningrank;

import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.swd1.gudong.R;
import com.example.swd1.gudong.constant.Constant;
import com.example.swd1.gudong.view.ReFreshView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by user on 9/12/16.
 */
public class RankFragment extends Fragment implements ReFreshView.OnRefreshListener {
    private ReFreshView rankList;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_rank, container, false);

        rankList = (ReFreshView) rootView.findViewById(R.id.rank_list);
        rankList.setOnRefreshListener(this);
        rankList.setAdapter(new RankListAdapter(getActivity()));
        return rootView;
    }

    /*-begin-20160913-shile.wu-add-for-task2781345-*/
    private mHandler mHandler = new mHandler();
    @Override
    public void onRefresh() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    Message message = new Message();
                    message.what = 1;
                    mHandler.sendMessage(message);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public class mHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1){
                rankList.setOnRefreshComplete();
            }
        }
    }
    /*-end-20160913-shile.wu-add-for-task2781345-*/
}
